package com.ffapp.helper.util;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.clj.fastble.utils.HexUtil;
import com.leon.lfilepickerlibrary.utils.StringUtils;

import java.io.UnsupportedEncodingException;
import java.util.Calendar;

import my.StringUtil;
import my.TimeUtils;

public class RulerUtil {

    public static String keyToValue(String key, String name, Context context){
        String value = key;

        switch (key) {
            case "梯形明渠":
                value = "0";
                break;

            case "矩形明渠":
                value = "1";
                break;

            case "U型明渠":
                value = "2";
                break;
            case "降水": {
                value = "P";
                break;
            }
            case "河道": {
                value = "H";
                break;
            }
            case "水库": {
                value = "K";
                break;
            }
            case "闸坝": {
                value = "Z";
                break;
            }
            case "泵站": {
                value = "D";
                break;
            }
            case "地下水": {
                value = "G";
                break;
            }
            case "水质": {
                value = "Q";
                break;
            }
            case "自报模式": {
                value = "0";
                break;
            }
            case "兼容模式": {
                value = "1";
                break;
            }
            case "水文自报式": {
                value = "2";
                break;
            }
            case "低": {
                value = "0";
                break;
            }
            case "中": {
                value = "1";
                break;
            }
            case "高": {
                value = "2";
                break;
            }
            case "关闭": {
                value = "0";
                break;
            }
            case "开启": {
                value = "1";
                break;
            }
        }

        if ("设备时间".equals(name) && !StringUtils.isEmpty(key)) {
            String time = TimeUtils.getTimeLongToStrByFormat(System.currentTimeMillis(), "yyyy/MM/dd,HH:mm:ss") + "," + Calendar.getInstance().getTime().getDay();
            StringBuilder sb = new StringBuilder(time);//构造一个StringBuilder对象
            sb.insert(0, "\"");
            sb.insert(key.length() - 1, "\"");
            value = sb.toString();
        }

        if ("遥测站分类码".equals(name)) {
            value = getTCode(key);
        }

        return value;
    }


    public static String getTCode(String key) {
        String value = "";
        switch (key) {
            case "P":
                value = "降水";
                break;
            case "降水":
                value = "P";
                break;
            case "H":
                value = "河道";
                break;
            case "河道":
                value = "H";
                break;
            case "K":
                value = "水库";
                break;
            case "水库":
                value = "K";
                break;
            case "Z":
                value = "闸坝";
                break;
            case "闸坝":
                value = "Z";
                break;
            case "D":
                value = "泵站";
                break;
            case "泵站":
                value = "D";
                break;
            case "G":
                value = "地下水";
                break;
            case "地下水":
                value = "G";
                break;
            case "Q":
                value = "水质";
                break;
            case "水质":
                value = "Q";
                break;
        }
        return value;
    }

}
